package com.yunhe.abnormal.client;

import com.yunhe.abnormal.client.fallback.DeviceFallbackFactory;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.base.PointDataTypeDTO;
import com.yunhe.common.model.device.Analog;
import com.yunhe.common.model.device.DeviceDTO;
import com.yunhe.common.model.device.EnergyUnitDTO;
import com.yunhe.common.model.model.AnalogRequestBody;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备Feign客户端
 * @author liuronglei
 */
@FeignClient(value = "ems-device", fallbackFactory = DeviceFallbackFactory.class)
public interface DeviceClient {

    /**
     * 根据ID查询设备
     */
    @RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<DeviceDTO>> getDeviceById(@PathVariable("id") Long id);

    @RequestMapping(value = "/devices/{id}/pathTitle", method = RequestMethod.GET)
    ResponseEntity<ResultObject<String>> getDevicePathTitleByDeviceId(@PathVariable("id") Long id);

    /**
     * 根据条件查询设备
     */
    @RequestMapping(value = "/devices", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<DeviceDTO>>> searchDevice(@RequestParam("deviceTypeId") Long deviceTypeId);

    /**
     * 根据ID获得能量单元对象
     * @param id ID
     */
    @RequestMapping(value = "/energyUnits/{id}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<EnergyUnitDTO>> getEnergyUnitById(@PathVariable("id") Long id);

    /**
     * 根据设备ID查询能量单元
     * @param deviceId 设备ID
     */
    @RequestMapping(value = "/energyUnits/byDeviceId", method = RequestMethod.GET)
    ResponseEntity<ResultObject<EnergyUnitDTO>> getEnergyUnitByDeviceId(@RequestParam("deviceId") Long deviceId);

    /**
     * 根据点号获得点表列表
     * @param pointNumber 点号
     */
    @RequestMapping(value = "/analogs/byPointNumber", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Analog>> getAnalogByPointNumber(@RequestParam("pointNumber") Long pointNumber);

    /**
     * 根据点号获得点表
     * @param pointNumbers
     * @return
     */
    @RequestMapping(value="/analogs/byPointNumbers", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<Analog>>> getAnalogsByPointNumbers(@RequestParam("pointNumbers") List<Long> pointNumbers);

    /**
     * 根据设备ID和点号数据类型获得点号
     * @param deviceId 设备ID
     * @param typeId 类型ID
     * @param typeName 类型name
     * @return
     */
    @RequestMapping(value = "/analogs/byDevAndTypeAndTerminal", method = RequestMethod.GET)
    ResponseEntity<ResultObject<Analog>> getAnalogByDevAndTypeAndTerminal(@RequestParam("deviceId") Long deviceId,
                                                                          @RequestParam("typeId") Long typeId,
                                                                          @RequestParam("typeName") String typeName);

    /**
     * 根据设备代码列表和点号数据类型列表获取点号列表
     * @param deviceId 设备代码列表
     * @param typeId 点号数据类型ID列表
     * @param typeName 点号数据类型名称列表
     */
    @RequestMapping(value = "/analogs/byDevAndType", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<Analog>>> getAnalogsByDevAndType(@RequestParam("deviceId") List<Long> deviceId,
                                                                      @RequestParam("typeId") List<Long> typeId,
                                                                      @RequestParam("typeName") List<String> typeName);

    @RequestMapping(value = "/analogs/alarm", method = RequestMethod.POST)
    ResponseEntity<ResultObject<Analog>> createAlarmAnalog(@RequestParam("objectId") Long objectId,
                                                           @RequestBody Analog analog);

    /**
     * 根据设备代码列表和点号数据类型列表获取点号列表
     * @param requestBody 需要填充设备ID列表deviceId
     * @param typeName     点号数据类型名称列表
     */
    @RequestMapping(value = "/analogs/byDevAndType", method = RequestMethod.POST)
    ResponseEntity<ResultObject<List<Analog>>> getAnalogsByDevAndTypeForPost(@RequestParam("typeName") List<String> typeName,
                                                                             @RequestBody AnalogRequestBody requestBody);

    /**
     * 根据ID获得点号数据类型
     * @param id
     * @return
     */
    @RequestMapping(value = "/pointDataTypes/{id}", method = RequestMethod.GET)
    ResponseEntity<ResultObject<PointDataTypeDTO>> getPointDataTypeById(@PathVariable("id") Long id);

    @RequestMapping(value = "/pointDataTypes/byPointNumbers", method = RequestMethod.GET)
    ResponseEntity<ResultObject<List<PointDataTypeDTO>>> getPointDataTypeByPointNumbers(@RequestParam("pointNumbers") List<Long> pointNumbers);

    @RequestMapping(value = "/pointDataTypes/byName", method = RequestMethod.GET)
    ResponseEntity<ResultObject<PointDataTypeDTO>> getPointDataTypeByName(@RequestParam("name") String name);

    @RequestMapping(value = "/pointDataTypes/byTitle", method = RequestMethod.GET)
    ResponseEntity<ResultObject<PointDataTypeDTO>> getPointDataTypeByTitle(@RequestParam("title") String title);
}
